package com.doone.telmarket.domain.factory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.doone.telmarket.domain.SiteDirectory;
import com.doone.telmarket.domain.SiteFile;
import com.doone.telmarket.domain.SitePath;
import com.doone.telmarket.domain.SiteResource;

/**
 * 
 * @author 吴同庆
 * @date 2009-9-18
 * @description 站点资源工厂
 * @package     com.doone.telmarket.domain.factory
 */
@Service
public class SiteResourceFactory {

	@Autowired
	private SitePathFactory sitePathFactory;

	@Autowired
	private SiteFileFactory siteFileFactory;

	public SiteResource createSiteResource(String oldFileNmae, String replacementName, SiteDirectory... siteDirectories) {
		SitePath sitePath = sitePathFactory.createSitePath(siteDirectories);
		SiteFile siteFile = siteFileFactory.createSiteFile(oldFileNmae, replacementName);
		SiteResource siteResource = new SiteResource(sitePath, siteFile);
		return siteResource;
	}

	public SiteResource createSiteResource(String pageName, SiteDirectory... siteDirectories) {
		SitePath sitePath = sitePathFactory.createSitePath(siteDirectories);
		SiteFile siteFile = siteFileFactory.createPage(pageName);
		SiteResource siteResource = new SiteResource(sitePath, siteFile);
		return siteResource;
	}
	
	public SiteResource createSiteResource(String pageUrl) {
		String[] dir =  pageUrl.split("/");
		return createSiteResource(dir[dir.length-1].replace(".html", ""),new SiteDirectory().createSiteDirectory(dir[1]),new SiteDirectory().createSiteDirectory(dir[2]));
	}

}
